<template>
  <a-drawer
    v-model:visible="vdata.visible"
    :title=" true ? '差异详情' : '' "
    :body-style="{ paddingBottom: '80px' }"
    width="40%"
    @close="onClose"
  >
    <a-row justify="space-between" type="flex">
      <a-col :sm="12">
        <a-descriptions :title="'差异类型：'+(vdata.detailData.diffType == 'local' ? '本地多帐' : vdata.detailData.diffType == 'channel' ? '渠道多帐' : vdata.detailData.diffType == 'order' ? '订单差异' : '其他')" />
      </a-col>
      <a-col :sm="12">
        <a-descriptions>
          <a-descriptions-item label="差异处理状态">
            {{ vdata.detailData.handleState === 0 ? '未处理': vdata.detailData.handleState === 1 ? '挂账': vdata.detailData.handleState === 2 ? '已处理': vdata.detailData.handleState === 3 ? '已忽略': '其他' }}
          </a-descriptions-item>
        </a-descriptions>
      </a-col>
      <a-col :sm="12">
        <a-descriptions>
          <a-descriptions-item label="批次号">
            {{ vdata.detailData.batchNo }}
          </a-descriptions-item>
        </a-descriptions>
      </a-col>
      <a-col :sm="12">
        <a-descriptions>
          <a-descriptions-item label="对账日期">
            {{ dateUtil.formatDate(vdata.detailData.billDate) }}
          </a-descriptions-item>
        </a-descriptions>
      </a-col>
      <a-col :sm="12">
        <a-descriptions>
          <a-descriptions-item label="支付接口">
            {{ vdata.detailData.ifCode }}
          </a-descriptions-item>
        </a-descriptions>
      </a-col>
      <a-col :sm="12">
        <a-descriptions>
          <a-descriptions-item label="渠道商户号">
            {{ vdata.detailData.channelMchNo }}
          </a-descriptions-item>
        </a-descriptions>
      </a-col>
      <a-col :sm="12">
        <a-descriptions>
          <a-descriptions-item label="平台订单号">
            {{ vdata.detailData.orderId }}
          </a-descriptions-item>
        </a-descriptions>
      </a-col>
      <a-col :sm="12">
        <a-descriptions>
          <a-descriptions-item label="账单类型">
            {{ vdata.detailData.billType === 'pay' ? '支付': '退款' }}
          </a-descriptions-item>
        </a-descriptions>
      </a-col>
      <a-col :sm="12">
        <a-descriptions>
          <a-descriptions-item label="差异处理者ID">
            {{ vdata.detailData.handleUid }}
          </a-descriptions-item>
        </a-descriptions>
      </a-col>
      <a-col :sm="12">
        <a-descriptions>
          <a-descriptions-item label="差异处理者姓名">
            {{ vdata.detailData.handleBy }}
          </a-descriptions-item>
        </a-descriptions>
      </a-col>
    </a-row>

    <a-divider v-if="vdata.detailData.diffType == 'local' || vdata.detailData.diffType == 'order'" orientation="left"><a-tag color="purple">本地订单信息</a-tag></a-divider>

    <a-row v-if="vdata.detailData.diffType == 'local' || vdata.detailData.diffType == 'order'" justify="space-between" type="flex">
      <a-col :sm="12">
        <a-descriptions>
          <a-descriptions-item label="订单状态">
            {{ vdata.detailData.orderState === 0?'订单生成':vdata.detailData.orderState === 1?'支付中':vdata.detailData.orderState === 2?'支付成功':vdata.detailData.orderState === 3?'支付失败':
              vdata.detailData.orderState === 4?'已撤销':vdata.detailData.orderState === 5?'已退款':vdata.detailData.orderState === 6?'订单关闭':'未知' }}
          </a-descriptions-item>
        </a-descriptions>
      </a-col>
      <a-col :sm="12">
        <a-descriptions>
          <a-descriptions-item label="交易金额">
            {{ (vdata.detailData.amount/100).toFixed(2) }}
          </a-descriptions-item>
        </a-descriptions>
      </a-col>
      <a-col :sm="12">
        <a-descriptions>
          <a-descriptions-item label="渠道手续费">
            {{ (vdata.detailData.feeAmount/100).toFixed(2) }}
          </a-descriptions-item>
        </a-descriptions>
      </a-col>
      <a-col :sm="12">
        <a-descriptions>
          <a-descriptions-item label="交易成功时间">
            {{ vdata.detailData.orderSuccessAt }}
          </a-descriptions-item>
        </a-descriptions>
      </a-col>
      <a-col v-if="vdata.detailData.channelUser" :sm="12">
        <a-descriptions>
          <a-descriptions-item label="商户号">
            {{ vdata.detailData.mchNo }}
          </a-descriptions-item>
        </a-descriptions>
      </a-col>
      <a-col v-if="vdata.detailData.mchName" :sm="12">
        <a-descriptions>
          <a-descriptions-item label="商户名称">
            {{ vdata.detailData.orgPayOrderId }}
          </a-descriptions-item>
        </a-descriptions>
      </a-col>
      <a-col v-if="vdata.detailData.mchAppId" :sm="12">
        <a-descriptions>
          <a-descriptions-item label="商户应用appId">
            {{ vdata.detailData.orgPayOrderId }}
          </a-descriptions-item>
        </a-descriptions>
      </a-col>
    </a-row>

    <a-divider v-if="vdata.detailData.diffType == 'channel' || vdata.detailData.diffType == 'order'" orientation="left"><a-tag color="purple">渠道订单信息</a-tag></a-divider>

    <a-row v-if="vdata.detailData.diffType == 'channel' || vdata.detailData.diffType == 'order'" justify="space-between" type="flex">
      <a-col :sm="12">
        <a-descriptions>
          <a-descriptions-item label="渠道订单状态">
            {{ vdata.detailData.channelState === 2 ? '支付成功' : vdata.detailData.channelState === 5 ? '退款成功' : '未知' }}
          </a-descriptions-item>
        </a-descriptions>
      </a-col>
      <a-col :sm="12">
        <a-descriptions>
          <a-descriptions-item label="渠道订单号">
            {{ vdata.detailData.channelOrderNo }}
          </a-descriptions-item>
        </a-descriptions>
      </a-col>
      <a-col :sm="12">
        <a-descriptions>
          <a-descriptions-item label="交易金额">
            {{ (vdata.detailData.channelAmount/100).toFixed(2) }}
          </a-descriptions-item>
        </a-descriptions>
      </a-col>
      <a-col :sm="12">
        <a-descriptions>
          <a-descriptions-item label="渠道手续费">
            {{ (vdata.detailData.channelFeeAmount/100).toFixed(2) }}
          </a-descriptions-item>
        </a-descriptions>
      </a-col>
      <a-col :sm="12">
        <a-descriptions>
          <a-descriptions-item label="渠道交易成功时间">
            {{ vdata.detailData.channelSuccessAt }}
          </a-descriptions-item>
        </a-descriptions>
      </a-col>
      <a-col v-if="vdata.detailData.channelUser" :sm="12">
        <a-descriptions>
          <a-descriptions-item label="渠道用户标识">
            {{ vdata.detailData.channelUser }}
          </a-descriptions-item>
        </a-descriptions>
      </a-col>
      <a-col v-if="vdata.detailData.orgPayOrderId" :sm="12">
        <a-descriptions>
          <a-descriptions-item label="退款原支付订单号">
            {{ vdata.detailData.orgPayOrderId }}
          </a-descriptions-item>
        </a-descriptions>
      </a-col>
    </a-row>
  </a-drawer>
</template>

<script lang="ts" setup>
import { API_URL_CHECK_DIFF_LIST, req } from '@/api/manage'
import {reactive} from 'vue'
import dateUtil from '@/utils/dateUtil.js'

const vdata:any = reactive({
  btnLoading: false,
  detailData: {}, // 数据对象
  recordId: null, // 更新对象ID
  visible: false, // 是否显示弹层/抽屉
})

function show (recordId) { // 弹层打开事件
  
  vdata.recordId = recordId
  req.getById(API_URL_CHECK_DIFF_LIST, recordId).then(res => {
    vdata.detailData = res
  })
  vdata.visible = true
}

function onClose () {
  vdata.visible = false
}

defineExpose({
  show //抛出show函数给父组件
})
</script>
